package com.medicine.hbp.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.medicine.hbp.base.MyBaseAdapter;
import com.medicine.hbp.mob.messageListVo;
import com.medicine.hbp.ui.ArtMeActivity;
import com.medicine.hbp.R;

public class UserListAdapter extends MyBaseAdapter {
	private LayoutInflater inflater;

	public UserListAdapter(Activity activity) {
		this.activity = activity;
		inflater = LayoutInflater.from(activity);
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		ViewHolder holder = null;
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.item_userlist, null);
			holder.textUserName = (TextView) view
					.findViewById(R.id.text_username);
			holder.textmsgcount = (TextView) view
					.findViewById(R.id.text_msgcount);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		final messageListVo listVo=(messageListVo) getItem(position);
		if(listVo!=null){
			holder.textUserName.setText(listVo.userName);
			holder.textmsgcount.setText(listVo.msgCount+"条");
		}
		view.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Intent intent=new Intent(activity,ArtMeActivity.class);
				intent.putExtra("UserId", listVo.userId);
				activity.startActivity(intent);
			}
		});
		return view;
	}

	class ViewHolder {
		TextView textUserName;
		TextView textmsgcount;

	}
}
